package ControlLayer;

import DBLayer.*;
import ModelLayer.*;

public class PersonController
{
    private DBPersonContainer personContainer;
    private DBCustomerContainer customerContainer;
    private DBCustomerTypeContainer customerTypeContainer;

    public PersonController()
    {
        personContainer = DBPersonContainer.getInstance();
        customerContainer = new DBCustomerContainer();
        customerTypeContainer = DBCustomerTypeContainer.getInstance();
    }

    public boolean createCustomer(String name, String adress, int zipCode, String phonenumber, String country, String email, int customerTypeID)
    {
        Person person = new Person(name, adress, zipCode, phonenumber, country, email);
        int personID = createPerson(person);

        int totalSpent = 0;
        boolean i = customerContainer.addCustomer(totalSpent, customerTypeID, personID);
        return i;
    }

    public int createPerson(Person pers)
    {
        int personID = personContainer.createPerson(pers);
        return personID;
    }

    public CustomerType getCustomerType(int customerTypeID)
    {
        return customerTypeContainer.getCustomerType(customerTypeID);
    }

    public Person getPerson(int personID)
    {
        DBPersonContainer container = new DBPersonContainer();
        return container.getPerson(personID);
    }

    public Person getPersonByPhoneNumber(String phoneNumber)
    {
        DBPersonContainer container = new DBPersonContainer();
        return container.getPerson("phoneNumber = " + phoneNumber);
    }
}
